﻿//=====================================================================================================
// LocalizationLibrary
// The Localization Library is a collection of reusable software components that provide 
// support for localization. This library enables you to localize WPF, Silverlight and WP7 applications.
// (http://localizationlibrary.codeplex.com)
//=====================================================================================================
// Author: Nicola Gallo (Website: www.nicola.gallo.name, Email: nicolagmt@hotmail.it) 
//=====================================================================================================

namespace LocalizationLibrary.Tests.Core.Attributes
{
    //.NET References
    using System;
    using System.Text;
    using System.Collections.Generic;
    using System.Linq;

    // Microsoft References
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    //LocalizationLibrary Referenes
    using LocalizationLibrary.Attributes;
    using System.Globalization;

    [TestClass]
    public class DynamicResourcePartAttributeTest
    {
            [TestMethod]
            public void New_Instance_Should_Assigns_All_Properties()
            {
            String resourceID = Guid.NewGuid().ToString();
            String language = "it";
            String text = Guid.NewGuid().ToString();

            DynamicResourcePartAttribute instance = new DynamicResourcePartAttribute(resourceID, language, text);

            Assert.AreEqual(instance.ResourceID, resourceID);
            Assert.AreEqual(instance.Language, language);
            Assert.AreEqual(instance.Value, text);

            instance.Policy = VersionConflictPolicy.KeepExisting;
            Assert.AreEqual(instance.Policy, VersionConflictPolicy.KeepExisting);

            instance.Policy = VersionConflictPolicy.OverrideExisting;
            Assert.AreEqual(instance.Policy, VersionConflictPolicy.OverrideExisting);
        }

        [ExpectedException(typeof(ArgumentException))]
        [TestMethod]
        public void New_Instance_Thrown_ArgumentException_If_ResourceID_Is_Null()
        {
            DynamicResourcePartAttribute instance =
                new DynamicResourcePartAttribute(null, Language.DefaultLanguage.Code, Guid.NewGuid().ToString());
        }

        [ExpectedException(typeof(ArgumentException))]
        [TestMethod]
        public void New_Instance_Thrown_ArgumentException_If_Value_Is_Null()
        {
            DynamicResourcePartAttribute instance =
                new DynamicResourcePartAttribute(Guid.NewGuid().ToString(), Language.DefaultLanguage.Code, null);
        }

        [ExpectedException(typeof(ArgumentException))]
        [TestMethod]
        public void New_Instance_Thrown_ArgumentException_If_ResourceID_Is_Equals_To_White_Space()
        {
            DynamicResourcePartAttribute instance =
                new DynamicResourcePartAttribute(String.Empty, Language.DefaultLanguage.Code, Guid.NewGuid().ToString());
        }

        [ExpectedException(typeof(ArgumentException))]
        [TestMethod]
        public void New_Instance_Thrown_ArgumentException_If_Language_Is_Invalid()
        {
            DynamicResourcePartAttribute instance =
                new DynamicResourcePartAttribute(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString());
        }

        [ExpectedException(typeof(ArgumentException))]
        [TestMethod]
        public void New_Instance_Thrown_ArgumentException_If_Text_Is_Null()
        {
            DynamicResourcePartAttribute instance =
                new DynamicResourcePartAttribute(Guid.NewGuid().ToString(), Language.DefaultLanguage.Code, null);
        }

        [ExpectedException(typeof(ArgumentException))]
        [TestMethod]
        public void New_Instance_Thrown_ArgumentException_If_Value_Is_Equals_To_White_Space()
        {
            DynamicResourcePartAttribute instance =
                new DynamicResourcePartAttribute(Guid.NewGuid().ToString(), Language.DefaultLanguage.Code, null);
        }

        [TestMethod]
        public void GetHashCode_Should_Be_Always_The_Same()
        {
            String resourceId = Guid.NewGuid().ToString();
            DynamicResourcePartAttribute instance = new DynamicResourcePartAttribute(resourceId, "it", new Object());
            Assert.AreEqual(instance.GetHashCode(), resourceId.GetHashCode());
        }

        [TestMethod]
        public void GetHashCode_Should_Be_Not_Equal()
        {
            DynamicResourcePartAttribute instance = new DynamicResourcePartAttribute(Guid.NewGuid().ToString(), "it", new Object());
            DynamicResourcePartAttribute instance2 = new DynamicResourcePartAttribute(Guid.NewGuid().ToString(), "it", new Object());
            Assert.AreNotEqual(instance.GetHashCode(), instance2.GetHashCode());
        }

        [TestMethod]
        public void Verify_If_Two_Instance_Are_Equals()
        {
            String resourceId = Guid.NewGuid().ToString();
            DynamicResourcePartAttribute instance = new DynamicResourcePartAttribute(resourceId, "it", new Object());

            Assert.AreEqual(instance.Equals(null), false);
            Assert.AreEqual(instance.Equals(instance), true);

            DynamicResourcePartAttribute instance2 = new DynamicResourcePartAttribute(resourceId, "it", new Object());

            Assert.AreEqual(instance.Equals(instance2), true);

            instance2 = new DynamicResourcePartAttribute(Guid.NewGuid().ToString(), "it", new Object());

            Assert.AreEqual(instance.Equals(instance2), false);
        }

        [ExpectedException(typeof(ArgumentException))]
        [TestMethod]
        public void Thrown_ArgumentException_If_Language_Is_Not_Valide()
        {
            DynamicResourcePartAttribute instance = new DynamicResourcePartAttribute(Guid.NewGuid().ToString(), null, new Object());
        }
    }
}
